package com.manlitech.manlichat.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.manlitech.manlichat.pojo.SessionInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;



import io.jsonwebtoken.Claims;
/**
 * 获取sessionInfo
 * @author Shensg
 *
 * 2020年5月3日
 */
@Component
public class SessionInfoUtils {

	@Autowired
	private RedisUtil redisUtil;

	/**
	 * websocket 唯一key
	 * @param accessToken
	 * @return
	 */
	public String getSessionInfoByAccessToken(String accessToken){
		Claims claims = JwtUtils.verifyJwt(accessToken);
		String uniqueKey = null;

		if(claims!=null){
			// 微信端
			if(claims.get("openid") != null){
				String openid = claims.get("openid").toString();
				String unionid = claims.get("unionid").toString();
				uniqueKey = "userid_0_unionid_"+unionid;
			}
			//后台管理系统
			if (claims.get("userId") != null) {
				String userId = claims.get("userId").toString();
				String name = claims.get("userName").toString();
				uniqueKey = "userid_"+userId+"_unionid_0";
			}
		}
		return uniqueKey;
	}


}
